package com.ws.hzuoj.admin.system.dictionary.web;

import cn.hutool.core.util.StrUtil;
import com.ws.common.easyui.util.Page;
import com.ws.common.easyui.util.PageUtils;
import com.ws.hzuoj.admin.system.dictionary.entity.DictionaryEntity;
import com.ws.hzuoj.admin.system.dictionary.service.IDictionaryEntityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;

@RequestMapping("/admin/system/dictionary/entity")
@Controller
public class DictionaryEntityWeb {


    @Autowired
    IDictionaryEntityService dictionaryEntityService;

    @RequestMapping("{type}")
    public String list(@PathVariable String type){
        return  null;
    }

    @RequestMapping("/listData")
    @ResponseBody
    public Object listData(DictionaryEntity dictionaryEntity,Page page){
        List<DictionaryEntity> dictionaryEntitys=dictionaryEntityService.list(dictionaryEntity,page);
        return PageUtils.getEasyUiList(dictionaryEntitys);
     }

    @RequestMapping("read")
    @ResponseBody
    public Object read(DictionaryEntity dictionaryEntity){
        if(StrUtil.isNotEmpty(dictionaryEntity.getId())){
            dictionaryEntity= dictionaryEntityService.read(dictionaryEntity.getId());
        }
        return  dictionaryEntity;
    }

    @RequestMapping("/save")
    @ResponseBody
    public Object save(DictionaryEntity dictionaryEntity){
        Integer count=dictionaryEntityService.save(dictionaryEntity);
        return  count;
     }

    @RequestMapping("/delete")
    @ResponseBody
    public Integer delete(String id){
        return  dictionaryEntityService.delete(id);
    }

    @RequestMapping("/insert")
    @ResponseBody
    public Object insert(DictionaryEntity dictionaryEntity){
        Integer count=dictionaryEntityService.insert(dictionaryEntity);
        return  count;
    }

    @RequestMapping("/insertSelective")
    @ResponseBody
    public Object insertSelective(DictionaryEntity dictionaryEntity){
        return dictionaryEntityService.insertSelective(dictionaryEntity);
    }

    @RequestMapping("/update")
    @ResponseBody
    public Object update(DictionaryEntity dictionaryEntity){
        return dictionaryEntityService.update(dictionaryEntity);
    }

    @RequestMapping("/listAll")
    @ResponseBody
    public Object listByMap(){
        return  dictionaryEntityService.listAll();
    }
}
